import { createApp, nextTick } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { createPinia } from 'pinia'
import router from './router'
import './styles/main.css'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import { useAuthStore } from './store/auth'
import { setupDBViewer } from './utils/dbViewer'

const app = createApp(App)

// 注册Element Plus（全局中文）
app.use(ElementPlus, { locale: zhCn })
// 注册所有Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
// 注册Pinia
const pinia = createPinia()
app.use(pinia)
// 注册Router
app.use(router)

app.mount('#app')

// 初始化数据库查看工具
setupDBViewer()

// 暂时注释掉初始化认证状态，避免错误
// nextTick(() => {
//   const authStore = useAuthStore()
//   if (authStore.initAuth) {
//     authStore.initAuth()
//   }
// })
